var Announcement = {
	Manage: {
		addWindowContainer: '',
		
		init: function() {
			Language.getCurrLanguage();
			Utils.loadJavascriptFile('/application/views/libraries/component/' + language + '.js');
			Utils.loadJavascriptFile('/application/views/libraries/utils/' + language + '.js');
			Utils.loadJavascriptFile('/application/views/module/Announcement/' + language + '.js');
			Utils.initAjax();
			
			Announcement.Manage.addWindowContainer = $('#addWindow');
			Announcement.Manage.AddWindow.init();
			Announcement.Manage.View.init();
		},
		
		View: {
			dataGridPanelContainer: '',
			
			init: function() {
				Announcement.Manage.View.dataGridPanelContainer = $('#dataGridPanel #dataGrid');
				Announcement.Manage.View.DataGrid.init();
			},
			
			DataGrid: {
				init: function() {
					Announcement.Manage.View.DataGrid.create();
				},
				
				create: function() {
					var width = $(document).width() - 40;
					var height = $(document).height() - 40;
					Announcement.Manage.View.dataGridPanelContainer.width(width);
					Announcement.Manage.View.dataGridPanelContainer.height(height);
					Announcement.Manage.View.dataGridPanelContainer.datagrid({
						url: '/index.php/Announcement/manage/getListData',
						idField: "id",
						toolbar: [
							{
								iconCls: 'icon-add',
								text: announcementManageViewDataGridToolbarButtonText1,
								handler: Announcement.Manage.AddWindow.open
							},
							{
								iconCls: 'icon-remove',
								text: announcementManageViewDataGridToolbarButtonText2,
								handler: Announcement.Manage.View.doRemoveAnnoucement
							},
						],
						columns: [[
							{
								field: 'content',
								title: announcementManageViewDataGridColumnTitle1,
								width: 600,
							},
							{
								field: 'startDatetime',
								title: announcementManageViewDataGridColumnTitle2,
								width: 150,
							},
							{
								field: 'endDatetime',
								title: announcementManageViewDataGridColumnTitle3,
								width: 150,
							},
							{
								field: 'timeInterval',
								title: announcementManageViewDataGridColumnTitle4,
								width: 80,
							},
							{
								field: 'operatorUserName',
								title: announcementManageViewDataGridColumnTitle5,
								width: 100,
							},
							{
								field: 'operatorDatetime',
								title: announcementManageViewDataGridColumnTitle6,
								width: 150,
							},
						]],
						loadFilter: Utils.dataGridLoadFilter,
						pagination: true,
						pageSize: 50,
						pageList: [50, 100, 150, 200],
					})
				},
				
				load: function() {
					Announcement.Manage.View.dataGridPanelContainer.datagrid('reload');
				},
				getCheckedRows: function(allowMulti) {
					var allowMulti = arguments[0] ? arguments[0] : false;
					var checkedRow = Announcement.Manage.View.dataGridPanelContainer.datagrid('getChecked');

					if(Utils.dataGridValidateCheckedRow(checkedRow, allowMulti) === true) {
						return checkedRow;
					}
					else {
						return false;
					}
				},
			},

			doRemoveAnnoucement: function() {
				var checkedRow = Announcement.Manage.View.DataGrid.getCheckedRows();

				if(checkedRow != false) {
					$.ajax({
							url: '/index.php/Announcement/manage/remove',
							data: {
								taskId: checkedRow[0].taskId,
							}
						})
						.done(function(response){
							if(response.errorCode === 0) {
								$.messager.alert(messageWindowTitle, announcementManageRemovrSuccessInfo, 'info');
								Announcement.Manage.View.DataGrid.load();
							}
						})
				}
			},
		},
		
		AddWindow: {
			gameAreaCombogridLabelContainer: '',
			gameAreaCombogridInputContainer: '',
			startDatetimeLabelContainer: '',
			startDateTimeInputContainer: '',
			endDatetimeLabelContainer: '',
			endDatetimeInputContainer: '',
			timeIntervalLabelContainer: '',
			timeIntervalInputContainer: '',
			contentLabelContainer: '',
			contentInputContainer: '',
			submitButtonContainer: '',
			resetButtonContainer: '',
			
			init: function() {
				Announcement.Manage.AddWindow.gameAreaCombogridLabelContainer = $('#addWindow #gameAreaCombogridLabel');
				Announcement.Manage.AddWindow.gameAreaCombogridInputContainer = $('#addWindow #gameAreaCombogridInput');
				Announcement.Manage.AddWindow.startDatetimeLabelContainer = $('#addWindow #startDatetimeLabel');
				Announcement.Manage.AddWindow.startDateTimeInputContainer = $('#addWindow #startDatetimeInput');
				Announcement.Manage.AddWindow.endDatetimeLabelContainer = $('#addWindow #endDatetimeLabel');
				Announcement.Manage.AddWindow.endDatetimeInputContainer = $('#addWindow #endDatetimeInput');
				Announcement.Manage.AddWindow.timeIntervalLabelContainer = $('#addWindow #timeIntervalLabel');
				Announcement.Manage.AddWindow.timeIntervalInputContainer = $('#addWindow #timeIntervalInput');
				Announcement.Manage.AddWindow.contentLabelContainer = $('#addWindow #contentLabel');
				Announcement.Manage.AddWindow.contentInputContainer = $('#addWindow #contentInput');
				Announcement.Manage.AddWindow.submitButtonContainer = $('#addWindow #submitButton');
				Announcement.Manage.AddWindow.resetButtonContainer = $('#addWindow #resetButton');
				
				Announcement.Manage.AddWindow.create();
			},
			
			create: function() {
				Announcement.Manage.addWindowContainer.window({
					title: announcementManageAddWindowTitle,
					collapsible: false,
					minimizable: false,
					maximizable: false,
					closable: true,
					closed: true,
					modal: true,
				})
				Component.Combogrid.GameArea.create(
					Announcement.Manage.AddWindow.gameAreaCombogridLabelContainer,
					Announcement.Manage.AddWindow.gameAreaCombogridInputContainer,
					true
				);
				Component.Datetimebox.Start.create(
					Announcement.Manage.AddWindow.startDatetimeLabelContainer,
					Announcement.Manage.AddWindow.startDateTimeInputContainer
				);
				Component.Datetimebox.End.create(
					Announcement.Manage.AddWindow.endDatetimeLabelContainer,
					Announcement.Manage.AddWindow.endDatetimeInputContainer
				);
				Component.Numberbox.TimeInterval.create(
					Announcement.Manage.AddWindow.timeIntervalLabelContainer,
					Announcement.Manage.AddWindow.timeIntervalInputContainer
				);
				Component.Textbox.Content.create(
					Announcement.Manage.AddWindow.contentLabelContainer
				);
				Announcement.Manage.AddWindow.submitButtonContainer.linkbutton({
					iconCls: 'icon-ok',
					text: announcementManageAddWindowSubmitButtonText,
				});
				Announcement.Manage.AddWindow.submitButtonContainer.bind(
					'click',
					Announcement.Manage.AddWindow.doSubmit
				);
				Announcement.Manage.AddWindow.resetButtonContainer.linkbutton({
					iconCls: 'icon-undo',
					text: announcementManageAddWindowResetButtonText,
				})
				Announcement.Manage.AddWindow.resetButtonContainer.bind(
					'click',
					Announcement.Manage.AddWindow.doReset
				);
			},
			
			open: function() {
				Announcement.Manage.AddWindow.reset();
				Announcement.Manage.addWindowContainer.window('open');
			},
			
			close: function() {
				Announcement.Manage.addWindowContainer.window('close');
			},
			
			doSubmit: function() {
				$.ajax({
					url: '/index.php/Announcement/manage/add',
					data: {
						gameAreaIdString: Announcement.Manage.AddWindow.gameAreaCombogridInputContainer.combogrid('getValues').toString(),
						startDatetime: Announcement.Manage.AddWindow.startDateTimeInputContainer.datetimebox('getValue'),
						endDatetime: Announcement.Manage.AddWindow.endDatetimeInputContainer.datetimebox('getValue'),
						timeInterval: Announcement.Manage.AddWindow.timeIntervalInputContainer.numberbox('getValue'),
						content: Announcement.Manage.AddWindow.contentInputContainer[0].value
					}
				})
				.done(function(response) {
					if(response.errorCode === 0) {
						$.messager.alert(messageWindowTitle, announcementManageAddWindowSubmitSuccessInfo, 'info');
						Announcement.Manage.AddWindow.close();
						Announcement.Manage.View.DataGrid.load();
					}
				})
			},
			
			doReset: function() {
				Announcement.Manage.AddWindow.reset();
			},
			
			reset: function() {
				Announcement.Manage.AddWindow.gameAreaCombogridInputContainer.combogrid('clear');
				Announcement.Manage.AddWindow.startDateTimeInputContainer.datetimebox('clear');
				Announcement.Manage.AddWindow.endDatetimeInputContainer.datetimebox('clear');
				Announcement.Manage.AddWindow.timeIntervalInputContainer.numberbox('clear');
				Announcement.Manage.AddWindow.contentInputContainer[0].value = '';
			},
		},
	},
}